package imageSmoother;

public class Solution {
    public int[][] imageSmoother(int[][] img) {
        //暴力解法
        int row = img.length;
        int clo = img[0].length;
        int[][] res = new int[row][clo];
        for(int i=0;i<row; i+=1){
            for(int j=0; j < clo; j+=1){
                int sum = 0;
                int count =0;
                for(int c_r =i -1; c_r <=i+1; c_r +=1){
                    //跳过超出边界的
                    if(c_r< 0 || c_r >= row){
                        continue;
                    }
                    for ( int c_c = j -1; c_c <= j+1; c_c +=1){
                        if(c_c <0 || c_c>=clo){
                            continue;
                        }
                        //累加
                        sum += img[c_r][c_c];
                        count +=1;
                    }

                }
                //求平均
                int avg = sum/count;
                //记录结果
                res[i][j] = avg;
            }

        }
        //返回结果
        return res;
    }
}
